<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>   
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
String path = request.getContextPath(); 
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";            
%>

<!DOCTYPE html>  
<html>
  <head>
    <base href="<%=basePath%>">   
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	 <title></title>
	<link rel="stylesheet" type="text/css" href="css/maintable.css" ></link>
	<script type="text/javascript" src="js/jquery-1.8.0.js"></script> 
	<script type="text/javascript">
		$(function(){	
			$("#ch_checkall,#top_ch_checkall").click(function(){
				if(this.checked){
					$("input[name=check_id]").attr("checked","checked");
				}else{
					$("input[name=check_id]").removeAttr("checked");
				}		
			});
					
			$("table tr").mouseover(function(){
				$(this).css("background","#D3EAEF");
				$(this).siblings().css("background","white");
			});
		});
	</script>
	<script type="text/javascript">
		function lock(id, isLock,pageIndex){
			var msg="";
			//0代表此时账号被锁定，1代表账号未锁定
			var state="";
			if(isLock){
				msg="确定要解锁该账号吗";
				lockState=0;
			}else{
				msg="确定要锁定该账号吗"
				lockState=1;
			}
			if(confirm(msg)){
				window.location.href="AdminServlet.do?flag=lock&id="+id+"&lockState="+lockState+"&pageIndex="+pageIndex;
			}
						
		}
		//右侧页面信息
		function pageRight(pageIndex){
			if(pageIndex){
				window.location.href="AdminServlet.do?flag=manage&pageIndex="+pageIndex;
			}else{
				window.location.href="AdminServlet.do?flag=manage&pageIndex="+$("#pageIndex").val();
			}
		}
		//删除一个
		function delOne(id,pageIndex){
			var adminid = '${session_admin.id}';
			if(confirm("确定要删除吗")){
			if(adminid==id){
				alert("不可以删除自己");
				return false;
			}else{
				window.location.href="AdminServlet.do?flag=del&id="+id+"&pageIndex="+pageIndex;
			}
			}
		}
		//点击上方的删除按钮,进行多项删除
		function delMore(pageIndex){
			var list=document.getElementsByName("check_id");
			var id = '${session_admin.id}';
			var idSql="";
			var flag=false;
			for(var i=0;i<list.length;i++){
				if(list[i].checked==true){
					if(list[i].value==id){
						alert("不可以删除自己");
						return false;
					}					
					idSql=idSql+list[i].value+",";
					flag=true;
				}
			}
			
			if(flag==true){
				window.location.href="AdminServlet.do?flag=delMore&idSql="+idSql;
				
			}else{
				alert("至少选中一个才可以删除");
				return false;
			}
		}
		
	</script>

	
  </head>
  
  <body>
  
    <div class ="div_title">
		<div class="div_titlename"> <img src="images/san_jiao.gif" ><span>管理人员基本信息列表</span></div>
		<div class="div_titleoper">
			<input type="checkbox" id="top_ch_checkall"/> 全选 
			<a href="admin/admin_add.jsp"> <img src="images/add.gif"/>添加 </a> 			         
			<a href="javascript:delMore()"><img src="images/del.gif"/>删除</a> 
		</div>
	</div>
				 
	<form action="AdminServlet.do"  name="form1">		
		<table class="main_table" >
			<tr>
				<th><input type="checkbox" id="ch_checkall" /></th>	<th>账号</th> 	<th>状态</th>	<th>备注</th>  <th>最后更新日期</th> 	<th>操作</th>
			</tr>
	 		<c:forEach var="admin" items="${adminList }">
				<tr>
					<td><input type="checkbox"  name="check_id" value="${admin.id }"></input></td>
				 	<td>${admin.adminName }</td>
				 	<td>
				 		<c:choose>
				 			<c:when test="${admin.state==0}">已锁定</c:when>
				 			<c:when test="${admin.state==1}"></c:when>
				 		</c:choose>
				 	</td>
				 	<td><label id="note_lable">${admin.note }</label></td>		
				 	<td><fmt:formatDate value="${admin.editDate}" pattern="yyyy-MM-dd hh:mm" /></td>	
				 	<td>
				 	<c:if test="${admin.state=='0'}">
				 			<a href="javascript:lock(${admin.id},true,${pageInfo.pageIndex })">解锁</a> |
				 			<a href="javascript:delOne(${admin.id},${pageInfo.pageIndex })" >删除</a>
				 	</c:if>
				 	<c:if test="${admin.state=='1'}">
				 			<a href="javascript:lock(${admin.id},false,${pageInfo.pageIndex })">锁定</a> |
				 			<a href="AdminServlet.do?flag=searchforupdate&id=${admin.id}"">修改</a> |
				 			<a href="javascript:delOne(${admin.id},${pageInfo.pageIndex })" >删除</a>
				 	</c:if>	
				 	</td> 			
				 </tr>
			</c:forEach>			 	
		</table>
	</form>
				
	<div class="div_page" >
		<div class="div_page_left">    共有 <label>${pageInfo.rowCount }</label> 条记录，当前第 <label>${pageInfo.pageIndex }</label> 页，共 <label>${pageInfo.pageCount }</label> 页	</div>		
		<div class="div_page_right" > 	 
			<c:choose>
				<c:when test="${pageInfo.hasPre }" >
					<button onclick="pageRight(1)" >首页</button>
					<button onclick="pageRight(${pageInfo.pageIndex-1})">上一页</button>	
				</c:when>
								  		
				<c:otherwise>
					首页
					上一页
				</c:otherwise>	
			</c:choose>
								  	
			<c:choose>
				<c:when test="${pageInfo.hasNext}" >
					<button onclick="pageRight(${pageInfo.pageIndex+1})">下一页</button>
					<button onclick="pageRight(${pageInfo.pageCount})">尾页</button>	
				</c:when>
								  		
				<c:otherwise>
					下一页 
					尾页
				</c:otherwise>	
			</c:choose>

		<button onclick="pageRight()">转到</button>
		 <input type="text" name="pageIndex" id="pageIndex" value="1" /> 页
					  	
		</div>
						
	</div>
	 <script type="text/javascript">
	  	 var msg='${msg}';
	  	 if(msg!=''){
	  	 	alert(msg);
	  	 }
	  </script>
  </body>
</html>